package top.anonyeast.controller;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 模拟根据城市名查询天气的Controller
 */
@RestController
@RequestMapping("/weather")
public class CityController {
    @CrossOrigin
    @GetMapping("/findByCity")
    public Map<String, String> findWeatherByCity(String city) {
        Map<String, String> map = new HashMap<>();
        String weather = getWeather(city);
        map.put("weatherInfo", weather);
        return map;
    }

    //返回对应城市的天气
    public String getWeather(String city) {
        //键值对：key是城市，value是天气
        Map<String, String> weathers = new HashMap<>();
        weathers.put("成都", "晴，空气一般。很热");
        weathers.put("自贡", "晴，空气清新，温度燥热");
        weathers.put("郑州", "暴雨，空气清新，发生自然灾害");
        weathers.put("杭州", "多云转晴，空气质量不错");
        weathers.put("上海", "晴转多云，空气也很好，局部地方大风");
        return weathers.get(city);
    }
}
